<%@ page language="java"  pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>    
    <title>miGLE Calculation</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">

	<link rel="stylesheet" type="text/css" href="css/miGLE.css"/>


    <script>
		function resetForm(){
			document.getElementById("f1").go.value = "-8" ;
			document.getElementById("f1").ge.value = "-8" ;
			document.getElementById("f1").en.value = "-10" ;
			document.getElementById("f1").sc.value = "100" ;
		}
		function clearForm(){
			document.getElementById("f1").go.value = "" ;
			document.getElementById("f1").ge.value = "" ;
			document.getElementById("f1").en.value = "" ;
			document.getElementById("f1").sc.value = "" ;
		}
	</script>
  </head>
  
<BODY>
<jsp:include page="head.html" />
<TABLE cellSpacing=0 cellPadding=0 width=800 align=center border=0>
  <TBODY>
  <TR>
    <TD width=790 rowSpan=2>
      <DIV align=center>
      <TABLE id=table1 cellSpacing=0 cellPadding=0 width="80%" border=0>
        <TBODY>
        <TR>
          <TD>
		  <form id="f1" action="servlet/MirandaServlet" method=post>
		  <table width="693" border="0" cellspacing="1" cellpadding="1">

            <tr>
              <td colspan="2"><div align="left"><strong><font face="Arial"><span class="MsoNormal"><span style="font-size: 10.5pt;"><span lang="en-us"><br>Overview of the user settings for miGLE analysis</span></span><span style="font-size: 10.5pt; font-family: Times New Roman;"><span lang="en-us"><span class="p"><span style="font-size: 10.5pt; font-family: Times New Roman;"><span lang="en-us">:<br><br></span></span></span></span></span></span></font></strong></div></td>
            </tr>
            
            <table>       
            <tr>
              <td width="20">&nbsp;</td>
              <td width="580"><div align="left">
                <p><%String filetype = session.getAttribute("filetype").toString();
                String fasta = session.getAttribute("seqfile").toString();
                String range = "";
                String sequence = "";
                StringBuilder seq = new StringBuilder();
           		StringBuilder number = new StringBuilder();
               	String[] line = fasta.split("\n");
               	int site = Integer.parseInt(session.getAttribute("site").toString());
               	int startSeq = Integer.parseInt(session.getAttribute("start").toString());
               	int startRange = site-10;
               	int endRange = site+10;

				out.print("<table><tr><td><span class=\"info\">Sequence</span></td></tr></table>");
   	            	for(int j=0; j<line.length; j++){
       	        		if(line[j].startsWith(">")){
       	        			out.print("<table  class=\"border\">");
           	    			out.print("<tr><td width=\"25\"></td><td width=\"120\"></td><td><br>" + line[j] + "\n" + "</td><td width=\"25\"></td></tr>");
           	    		}else{
           	    			number.append((startSeq+60*(j-1)) + "-" + (startSeq+60*j) + "\t\n");
							for (int k = 0; k < line[j].length(); k++) {
								seq.append(line[j].charAt(k));
							}           	    			
           	    		}
               		}
               		sequence = seq.toString();
               		int length = sequence.length();
               		if(startRange < startSeq){
               			startRange = startSeq;
               		}
               		if(endRange > (startSeq + length -1)){
               			endRange = startSeq + length -1;
               		}
         		
               		range = sequence.substring(startRange-startSeq, endRange-startSeq+1);
               		String range_tag = "<span class=\"yellow\">" + range.substring(0, site-startRange)
               				+ "<span class=\"red\">" + range.substring(site-startRange, site-startRange+1)
               				+ "</span>" + range.substring(site-startRange+1, range.length())
               				+ "</span>";
               		
               		String sequence_tag = sequence.substring(0, startRange-startSeq) + range_tag
               				+ sequence.substring(endRange-startSeq+1, length);
               		              		
             		seq = new StringBuilder();
               		int count = 0;
               		for (int k = 0; k < sequence_tag.length(); k++) {
						seq.append(sequence_tag.charAt(k));
						if(sequence_tag.charAt(k)=='A' || sequence_tag.charAt(k)=='T' || 
							sequence_tag.charAt(k)=='G' || sequence_tag.charAt(k)=='C'){
							
							count++;
							if (count % 60 == 0) {
								seq.append("\n");
								continue;
							}
							if (count % 10 == 0) {
								seq.append("  ");
							}
						}
					}
					out.print("<tr><td width=\"25\"></td><td width=\"120\"><pre>" + number.toString() + "</pre></td><td><pre>");
               		out.print(seq.toString());
               		out.print("</pre></td><td width=\"25\"></td></tr></table>");
               		
               		out.print("<table><tr><td width=\"150\" height=\"20\"></td></tr>");
               		out.print("<tr><td width=\"150\" height=\"20\"><span class=\"info\">Sequence Format: </span></td><td><span class=\"info\">" + filetype.toUpperCase() +"</span></td></tr>");
               		out.print("<tr><td width=\"150\" height=\"20\"><span class=\"info\">Core Site: </span></td><td><span class=\"info\">" + site + " <span class=\"red\">" + sequence.substring(site-startSeq, site-startSeq+1) + "</span></span></td></tr>");
               		out.print("<tr><td width=\"150\" height=\"20\"><span class=\"info\">Mutation Range: </span></td><td><span class=\"info\">" + startRange + " — " + endRange + "   " + range_tag + "</span></td></tr>");
               		out.print("<tr><td width=\"150\" height=\"20\"></td></tr></table>");
                %></p>
              </div></td>
            </tr>
            </table>
            <tr>
              <td colspan="2"><div align="left"><strong><font face="Arial"><span class="MsoNormal"><span style="font-size: 10.5pt;"><span lang="en-us"><hr width=\"580\"/><br>Set calculating parameters </span></span><span style="font-size: 10.5pt; font-family: Times New Roman;"><span lang="en-us"><span class="p"><span style="font-size: 10.5pt; font-family: Times New Roman;"><span lang="en-us">:<br><br></span></span></span></span></span></span></font></strong></div></td>
            </tr>			

			<table>
			<tr>
				<td width="10"><font face="Arial">&nbsp;</font></td>
				<td width="150"><div align="left">
				gap-open &nbsp;  
                <input name="go" size="4" value="-8"/></div>
			    </td>
				<td width="150"><div align="left">
				gap-extend &nbsp;  
                <input name="ge" size="4" value="-8"/></div>
			    </td>
			    <td width="150"><div align="left">&nbsp;&nbsp;&nbsp;&nbsp; energy &nbsp;  
                <input name="en" size="4" value="-10"/></div>
			    </td>
			    <td width="150"><div align="left">&nbsp;&nbsp; score &nbsp;  
                <input name="sc" size="4" value="100"/></div>
			    </td>
			 </tr>
			</table>
            
            <table>
            <tr>
            <td width="10">&nbsp;</td>
            </tr>
            </table>
            
			<table align="left">
            <tr>
              <td width="90">
			  	<br>
			  </td>
			  <td width="40"><div align="left">
                  <INPUT type=submit value="  Submit  "> </div>
			  </td>
			  <td width="330"><br></td>
			  <td width="40"><div align="left">
			  	<input type=button value=" Default " onclick="resetForm()" /></div>
			  </td>
			  <td width="40"><div align="left">
	          	<INPUT type=button value="  Clear  " onclick="clearForm()"></div>	  
			  </td>

			</tr>
          	</table>
          </table>
		  </form>
        </TR></TBODY></TABLE></DIV></TD></TR>
	  </TBODY>
	  </TABLE>
<jsp:include page="end.jsp" />
</BODY>
</html>


